﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Edit.aspx.cs" Inherits="MonkeyWarranty.Web.InstantTickets.Edit" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <title><%=Resources.GlobalStrings.InstantTickets %></title>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h2>
        <%=Resources.GlobalStrings.InstantTicketForm %> - <%=Resources.GlobalStrings.InstantTickets %></h2>
    <p>
    </p>
    <span class="failureNotification">
        <asp:Literal ID="lblErrorMessage" runat="server"></asp:Literal>
    </span>
    
    <!-- Customer -->
    <div>
        <fieldset class="register">
            <legend><%=Resources.GlobalStrings.Customers%></legend>
            <asp:HiddenField ID="hidCustomerId" runat="server" />
            <%=Resources.GlobalStrings.Name %><asp:TextBox ID="txtName" runat="server" CssClass="textEntry name"></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="txtName"
                        CssClass="failureNotification" ValidationGroup="AddNew">(*)</asp:RequiredFieldValidator>
            <%=Resources.GlobalStrings.Phone %><asp:TextBox ID="txtPhone" runat="server" CssClass="textEntry name"></asp:TextBox>
            <%=Resources.GlobalStrings.Address %><asp:TextBox ID="txtAddress" runat="server" CssClass="textEntry name"></asp:TextBox>
            <%=Resources.GlobalStrings.Email %><asp:TextBox ID="txtEmail" runat="server" CssClass="textEntry name"></asp:TextBox>
        </fieldset>
    </div>
    <!-- End Customer -->
    
    <!-- Common information -->
    <div>
        <fieldset class="register">
            <legend><%=Resources.GlobalStrings.Information %></legend>
            <%=Resources.GlobalStrings.TicketNumber %>
            <asp:TextBox ID="txtCodePrefix" runat="server" Enabled="False" Text="TN" CssClass="textEntry codeprefix"></asp:TextBox> - 
            <asp:TextBox ID="txtCode" runat="server" Enabled="False" CssClass="textEntry codeprefix"></asp:TextBox>
            <%=Resources.GlobalStrings.ReceivedDate %><asp:TextBox ID="txtReceivedDate" runat="server" CssClass="textEntry date"></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtReceivedDate"
                        CssClass="failureNotification" ValidationGroup="AddNew">(*)</asp:RequiredFieldValidator>
            <%=Resources.GlobalStrings.ReceivedEmployee %><asp:DropDownList ID="ddlEmployees" runat="server"></asp:DropDownList>
            <p></p>
            <%=Resources.GlobalStrings.Content %> 
            <asp:TextBox ID="txtContent" runat="server" CssClass="textEntry content"></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtContent"
                        CssClass="failureNotification" ValidationGroup="AddNew">(*)</asp:RequiredFieldValidator>
            <%=Resources.GlobalStrings.Distance %> 
            <asp:TextBox ID="txtDistance" runat="server" CssClass="textEntry codeprefix" Text="0,00"></asp:TextBox>
            <p></p>
            <%=Resources.GlobalStrings.Status %>
            <asp:DropDownList ID="ddlTicketStatus" runat="server">
            </asp:DropDownList>
            <p></p>
            <asp:Button ID="btnSave" runat="server" Text="<%$ Resources:GlobalStrings, Save %>"
            CssClass="submitButton" ValidationGroup="AddNew" OnClick="btnSave_Click" />
            <input id="btnPrint" type="button" value="<%=Resources.GlobalStrings.Print %>" class="submitButton"  onclick="javascript:window.open('PrintTicket.aspx?id=<%=Request.Params["id"] %>');" />
            <asp:Button ID="btnCopyToWarranty" runat="server" Text="<%$ Resources:GlobalStrings, CopyToWarranty %>" OnClick="btnCopyToWarranty_Click" />
        </fieldset>
    </div>
    <!-- End common -->
    
    <!-- Details -->
    <div>
        <fieldset class="register">
            <legend><%=Resources.GlobalStrings.Details %></legend>
            <div id="tabs" class="ui-tabs ui-widget ui-widget-content ui-corner-all">
	            <ul class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all">
		            <li class="ui-state-default ui-corner-top ui-tabs-selected ui-state-active"><a href="#tabs-1"><%=Resources.GlobalStrings.OutsideService %></a></li>
                    <li class="ui-state-default ui-corner-top"><a href="#tabs-2"><%=Resources.GlobalStrings.AtCompany %></a></li>
		            <li class="ui-state-default ui-corner-top"><a href="#tabs-3"><%=Resources.GlobalStrings.WarrantyEmployees %></a></li>
	            </ul>
	            <div id="tabs-1" class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide">
		            <div id="ServicesTableContainer"></div>
                    <p>
                        <a href="NewService.aspx?ticketId=<%=Request.Params["id"] %>"><%=Resources.GlobalStrings.AddNew %></a>
                    </p>
	            </div>
	            <div id="tabs-2" class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide">
		            <div id="ProductsTableContainer"></div>
                    <p>
                        <a href="NewProduct.aspx?ticketId=<%=Request.Params["id"] %>"><%=Resources.GlobalStrings.AddNew %></a>
                    </p>
	            </div>
	            <div id="tabs-3" class="ui-tabs-panel ui-widget-content ui-corner-bottom">
		            <div id="EmployeesTableContainer"></div>
                    <p>
                        <a href="NewEmployee.aspx?ticketId=<%=Request.Params["id"] %>"><%=Resources.GlobalStrings.AddNew %></a>
                    </p>
	            </div>
            </div>
        </fieldset>
    </div>
    <!-- End details -->
    
    <p>
    </p>
    <div>
        <input id="btnCancel" type="button" value="<%=Resources.GlobalStrings.Cancel %>"
            class="submitButton" onclick="javascript:window.location='List.aspx';" />
    </div>

    <script type="text/javascript">
        $(document).ready(function () {
            $("#<%=txtReceivedDate.ClientID %>").calendar();
            $("#tabs").tabs();

            $("#dialog:ui-dialog").dialog("destroy");
            $("#customers-dialog-form").dialog({
                autoOpen: false,
                height: 400,
                width: 800,
                modal: true
            });

            LoadProducts();
            LoadServices();
            LoadEmployees();
        });
    </script>
    
    <script type="text/javascript">
        function CustomerSelect(customer) {
            $("#customers-dialog-form").dialog("close");
            //console.debug(customer);
            $("#<%=hidCustomerId.ClientID %>").val(customer.Id);
            $("#<%=txtName.ClientID %>").val(customer.Name);
            $("#<%=txtAddress.ClientID %>").val(customer.Address);
            $("#<%=txtPhone.ClientID %>").val(customer.Phone);
            $("#<%=txtEmail.ClientID %>").val(customer.Email);
        }

        function NewCustomer() {
            //$("#customers-dialog-form").dialog("close");
            $("#<%=txtName.ClientID %>").prop("disabled", false);
            $("#<%=txtAddress.ClientID %>").prop("disabled", false);
            $("#<%=txtPhone.ClientID %>").prop("disabled", false);
            $("#<%=txtEmail.ClientID %>").prop("disabled", false);
            $("#<%=txtName.ClientID %>").val('');
            $("#<%=txtAddress.ClientID %>").val('');
            $("#<%=txtPhone.ClientID %>").val('');
            $("#<%=txtEmail.ClientID %>").val('');
            $("#<%=txtName.ClientID %>").focus();
        }

        function SelectCustomer() {
            $("#<%=hidCustomerId.ClientID %>").val(0);
            $("#<%=txtName.ClientID %>").val('');
            $("#<%=txtAddress.ClientID %>").val('');
            $("#<%=txtPhone.ClientID %>").val('');
            $("#<%=txtEmail.ClientID %>").val('');
            // read only customer data
            $("#<%=txtName.ClientID %>").prop("disabled", true);
            $("#<%=txtAddress.ClientID %>").prop("disabled", true);
            $("#<%=txtPhone.ClientID %>").prop("disabled", true);
            $("#<%=txtEmail.ClientID %>").prop("disabled", true);
            // load data
            $("#customers-dialog-form").dialog("open");
            $('#LoadRecordsButton').click();
        }
        
        function LoadProducts() {
            $('#ProductsTableContainer').jtable({
                //title: '<%=Resources.GlobalStrings.ProductsList %>',
                paging: false,
                pageSize: 10,
                sorting: false,
                //defaultSorting: 'Name ASC',
                actions: {
                    listAction: 'Edit.aspx/TicketProductList',
                    //createAction: 'List.aspx/CreateProduct',
                    //updateAction: 'List.aspx/UpdateProduct',
                    deleteAction: 'Edit.aspx/TicketDeleteProduct'
                },
                fields: {
                    Id: {
                        key: true,
                        create: false,
                        edit: false,
                        list: false
                    },
                    ProductCode: {
                        title: '<%=Resources.GlobalStrings.Code %>'
                    },
                    ProductName: {
                        title: '<%=Resources.GlobalStrings.Name %>'
                    },
                    Model: {
                        title: '<%=Resources.GlobalStrings.Model %>'
                    },
                    ManufacturerName: {
                        title: '<%=Resources.GlobalStrings.Manufacturers %>'
                    },
                    Serial: {
                      title: '<%=Resources.GlobalStrings.Serial %>'  
                    },
                    Quantity: {
                        title: '<%=Resources.GlobalStrings.Quantity %>'
                    },
                    WarrantyTypeName: {
                        title: '<%=Resources.GlobalStrings.WarrantyType %>'
                    },
                    ErrorName: {
                        title: '<%=Resources.GlobalStrings.ErrorCode %>'
                    },
                    WarrantyDate: {
                        title: '<%=Resources.GlobalStrings.WarrantyDate %>',
                        type: 'date',
                        displayFormat: 'dd/mm/yy'
                    },
//                    Months: {
//                        title: 'So thang BH'
//                    },
                    //WarrantyCount: {title: 'Lan BH'},
                    SupplierName: {title: '<%=Resources.GlobalStrings.Suppliers %>'},
//                    Description: {
//                        title: '<%=Resources.GlobalStrings.Description %>',
//                        type: 'textarea'
//                    },
                    Edit: {
                        title: '',
                        width: '1%',
                        display: function (data) {
                            return '<input class="jtable-command-button jtable-edit-command-button" onclick="javascript:window.location=\'EditProduct.aspx?id=' + data.record.Id + '\';" />';
                        }
                    }
                }
            });

            $('#ProductsTableContainer').jtable('load', { ticketId: <%=Request.Params["id"] %> });
        }
        
        function LoadServices() {
            $('#ServicesTableContainer').jtable({
                paging: false,
                pageSize: 10,
                sorting: false,
                actions: {
                    listAction: 'Edit.aspx/TicketServiceList',
                    deleteAction: 'Edit.aspx/TicketDeleteService'
                },
                fields: {
                    Id: {
                        key: true,
                        create: false,
                        edit: false,
                        list: false
                    },
                    ServiceName: {
                        title: '<%=Resources.GlobalStrings.Name %>'
                    },
                    Quantity: {
                        title: '<%=Resources.GlobalStrings.Quantity %>'
                    },
                    ServiceTypeName: {
                        title: '<%=Resources.GlobalStrings.ServiceType %>'
                    },
                    ErrorName: {
                        title: '<%=Resources.GlobalStrings.ErrorCode %>'
                    },
                    Edit: {
                        title: '',
                        width: '1%',
                        display: function(data) {
                            return '<input class="jtable-command-button jtable-edit-command-button" onclick="javascript:window.location=\'EditService.aspx?id=' + data.record.Id + '\';" />';
                        }
                    }
                }
            });

            $('#ServicesTableContainer').jtable('load', { ticketId: <%=Request.Params["id"] %> });
        }
        
        function LoadEmployees() {
            $('#EmployeesTableContainer').jtable({
                paging: false,
                pageSize: 10,
                sorting: false,
                actions: {
                    listAction: 'Edit.aspx/TicketEmployeeList',
                    deleteAction: 'Edit.aspx/TicketDeleteEmployee'
                },
                fields: {
                    Id: {
                        key: true,
                        create: false,
                        edit: false,
                        list: false
                    },
                    StartDate: {
                        title: '<%=Resources.GlobalStrings.StartDate %>',
                        type: 'date',
                        displayFormat: 'dd/mm/yy'
                    },
                    EmployeeName: {
                        title: '<%=Resources.GlobalStrings.Name %>'
                    },
                    Description: {
                        title: '<%=Resources.GlobalStrings.Description %>'
                    },
                    Edit: {
                        title: '',
                        width: '1%',
                        display: function(data) {
                            return '<input class="jtable-command-button jtable-edit-command-button" onclick="javascript:window.location=\'EditEmployee.aspx?id=' + data.record.Id + '\';" />';
                        }
                    }
                }
            });

            $('#EmployeesTableContainer').jtable('load', { ticketId: <%=Request.Params["id"] %> });
        }
    </script>
</asp:Content>
